package hu.szyrt.bug;

import java.util.ArrayList;

import hu.szyrt.bug.adapters.GalleryAdapter;
import hu.szyrt.bug.pageindicators.CirclePageIndicator;
import hu.szyrt.bug.utils.Assets;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.view.ViewPager;

public class GalleryActivity extends Activity {

	public final static String KEY_IMAGES = "images";
	
	Assets assets;	
	GalleryAdapter adapter;
	ViewPager pager;
	CirclePageIndicator indicator;
	
	String[] images;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.gallery);
		
		// Adat levétel		
		if(getIntent().getExtras() != null && getIntent().getExtras().containsKey(KEY_IMAGES))
			images = getIntent().getExtras().getStringArray(KEY_IMAGES);
		
		// Takarítás
		ArrayList<String> realImages = new ArrayList<String>();
		for(String image : images)
			if(image != null && image.length() > 0)
				realImages.add(image);
		images = realImages.toArray(new String[]{});
		
		if(images == null || images.length == 0){
			finish();
			return;
		}
			
		
		this.assets = new Assets(this);
		this.adapter = new GalleryAdapter(assets, images);
		this.pager = (ViewPager)findViewById(R.id.pager);
		this.pager.setAdapter(adapter);
		this.indicator = (CirclePageIndicator)findViewById(R.id.indicator);
		this.indicator.setViewPager(pager);
	}
	
	
	public static void open(Context context, String[] images){
		Intent i = new Intent(context, GalleryActivity.class);
		       i.putExtra(KEY_IMAGES, images);
		context.startActivity(i);
	}
	
}
